package com.wwp.tbshop.activity;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.wwp.tbshop.R;
import com.wwp.tbshop.event.SaleNewsCartEventbus;
import com.wwp.tbshop.model.adapter.NewGoodsRVAdapater;
import com.wwp.tbshop.model.bean.NewGoodsBean;
import com.wwp.tbshop.presenter.NewGoodsPresenter;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by ${wenping} on 6/16/2017.
 */

public class NewGoodsActivity extends BaseActivity {

    @Bind(R.id.sale_news_loading)
    RelativeLayout mSaleNewsLoading;
    @Bind(R.id.limt_buy_back)
    ImageView mLimtBuyBack;
    @Bind(R.id.limt_buy_cart)
    ImageView mLimtBuyCart;
    @Bind(R.id.limt_buy_recycleview)
    RecyclerView mLimtBuyRecycleview;

    private NewGoodsRVAdapater mNewGoodsRVAdapater;

    @Override
    public int getLayoutId() {
        return R.layout.activity_new_goods;
    }

    @Override
    protected void init() {
        super.init();

//        mNewGoodsPlv.setAdapter();
        mLimtBuyRecycleview.setLayoutManager(new GridLayoutManager(this, 2));
        NewGoodsPresenter mNewGoodsPresenter = new NewGoodsPresenter(this);
        mNewGoodsPresenter.loadNewGoods();
        mLimtBuyRecycleview.setLayoutManager(new GridLayoutManager(this, 2));
        mNewGoodsRVAdapater = new NewGoodsRVAdapater(this, this);
        mLimtBuyRecycleview.setAdapter(mNewGoodsRVAdapater);
    }

    @OnClick({R.id.limt_buy_back, R.id.limt_buy_cart})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.limt_buy_back:
                finish();
                break;
            case R.id.limt_buy_cart:
                //跳转到购物车;有问题呢;
                SaleNewsCartEventbus eventbus = new SaleNewsCartEventbus();
                eventbus.SalenewsToMain(this);
                EventBus.getDefault().post(eventbus);
                break;
        }
    }

    public void onLimitBuySuccess(List<NewGoodsBean.ProductListBean> list) {
        mNewGoodsRVAdapater.setProductListBeanList(list);
    }
}
